//
//  BGNewFeatureViewController.swift
//  WeiboSwift
//
//  Created by 战场原黑仪 on 16/7/24.
//  Copyright © 2016年 战场原黑仪. All rights reserved.
//

import UIKit

private let identifier = "cell"

class BGNewFeatureViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.setupUI()
        self.setupLayout()
    }
    
    //MARK: - 设置视图
    private func setupUI() {
        self.view.addSubview(collectionView)
    }
    
    private func setupLayout() {
        collectionView.snp_makeConstraints { (make) in
            make.edges.equalTo(view)
        }
    }
    
    //MARK: - 懒加载
    private lazy var collectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        
        layout.itemSize = CGSizeMake(SCREEN_W, SCREEN_H)
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        layout.scrollDirection = .Horizontal
        
        let collect = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
        //设置代理
        collect.dataSource = self
        collect.delegate = self
        //注册cell
        collect.registerClass(BGNewFeatureCell.self, forCellWithReuseIdentifier: identifier)
        
        //取消滚动条
        collect.showsHorizontalScrollIndicator = false
        collect.showsVerticalScrollIndicator = false
        //取消弹簧
        collect.bounces = false
        //设置分页
        collect.pagingEnabled = true
        
        return collect
    }()
    
}

//MARK: - collection代理方法
extension BGNewFeatureViewController: UICollectionViewDelegate, UICollectionViewDataSource {
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: indexPath) as? BGNewFeatureCell
        cell!.imageIndex = indexPath.item
        
        if indexPath.item == 3 {
            cell!.showStartButton()
        }
        
        return cell!
    }
    
}

